package org.igeek.config.bean.ch01;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @package org.igeek.config.ch01
 * @Description 通过config的配置类扫描  @componentScan+@Component 标识bean
 * @Author LittlePunk [296526219@qq.ccom]
 * @Version 2022.1
 * @Date 2023/11/13 15:12
 */
public class MainTest {
    public static void main(String[] args) {

        /* 方法一：通过@componentsacn+@component */
        //1.创建ioc容器
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(MyConfig.class);
        //2.获取person实例
        //Person person = ac.getBean("person", Person.class);
        //使用
        //person.setUsername("张三");
        //person.setPassword("1234");
        //System.out.println("person = " + person);

        System.out.println("-----------------------------");
        /* 方法二：通过@Bean的方式来创建实例对象  name是bean加载的方法名 */
        Person pp = ac.getBean("pp", Person.class);
        System.out.println("pp = " + pp);
    }
}
